package cn.tedu.luban.worker.main.repository.Impl;

import cn.tedu.luban.worker.main.converter.WorkerCategoryConverter;
import cn.tedu.luban.worker.main.mapper.WorkerCategoryMapper;
import cn.tedu.luban.worker.main.repository.IWorkerCategoryRepository;
import cn.tedu.luban.worker.protocol.bo.WorkerCategoryBO;
import cn.tedu.luban.worker.protocol.dos.WorkerCategoryDO;
import cn.tedu.luban.worker.protocol.param.WorkerRegistCategoryParam;
import cn.tedu.luban.worker.protocol.param.WorkerRegistParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

@Repository
public class WorkerCategoryRepositoryImpl implements IWorkerCategoryRepository {
    @Autowired
    private WorkerCategoryMapper workerCategoryMapper;

    @Override
    public void delete(Long userId) {
        workerCategoryMapper.deleteByUserId(userId);
    }

    @Autowired
    private WorkerCategoryConverter workerCategoryConverter;
    @Override
    public void saveWorkerCategories(WorkerRegistParam param) {
        List<WorkerRegistCategoryParam> categoryParams = param.getWorkerRegistCategoryParams();
        //1. param中 List<WorkerRegistCategoryParam> 转化
        List<WorkerCategoryDO> dos =
                workerCategoryConverter.params2dos(categoryParams,param.getUserId());
        //2. 批量新增
        workerCategoryMapper.batchInsert(dos);
    }

    @Override
    public List<WorkerCategoryBO> findCategories(Long userId) {
        List<WorkerCategoryDO> dos=workerCategoryMapper.selectByUserId(userId);
        return workerCategoryConverter.dos2bos(dos);
    }
}
